﻿Imports System.Activities
Imports System.Activities.Presentation.Metadata
Imports System.Drawing
Imports System.ComponentModel

Public Class SetHashtableValue
    Inherits CodeActivity
    Implements IRegisterMetadata

    Public Property HashArgument As InOutArgument(Of Hashtable)
    Public Property KeyName As InArgument(Of String)
    Public Property Values As InArgument(Of Object)

    Public Sub New()
        Me.DisplayName = My.Resources.SetHashtableValueDisplayName
    End Sub

    Protected Overrides Sub Execute(context As System.Activities.CodeActivityContext)
        Dim ht = context.GetValue(Me.HashArgument)
        Dim key = context.GetValue(Me.KeyName)
        Dim vals = context.GetValue(Me.Values)

        If ht.ContainsKey(key) Then
            ht.Item(key) = vals
        Else
            ht.Add(key, vals)
        End If

        context.SetValue(Me.HashArgument, ht)
    End Sub


    Public Sub Register() Implements System.Activities.Presentation.Metadata.IRegisterMetadata.Register
        Dim build As New AttributeTableBuilder
        'SetHashtableValue Activity
        build.AddCustomAttributes(GetType(SetHashtableValue),
                                              New DesignerAttribute(GetType(SetHashtableValueDesigner)),
                                              New ToolboxBitmapAttribute(GetType(SetHashtableValue), "SetHashtableValue.png"))

        build.AddCustomAttributes(GetType(SetHashtableValue), "DisplayName",
                                      New CategoryAttribute(My.Resources.CategorySetting),
                                      New DisplayNameAttribute(My.Resources.DisplayNameDisplay))

        build.AddCustomAttributes(GetType(SetHashtableValue), "HashArgument",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New RequiredArgumentAttribute(),
                                      New DisplayNameAttribute(My.Resources.HashArgumentDisplay),
                                      New DescriptionAttribute(My.Resources.HashArgumentDisplay))
        build.AddCustomAttributes(GetType(SetHashtableValue), "KeyName",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New RequiredArgumentAttribute(),
                                      New DisplayNameAttribute(My.Resources.KeyNameDisplay),
                                      New DescriptionAttribute(My.Resources.KeyNameDescription))
        build.AddCustomAttributes(GetType(SetHashtableValue), "Values",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New DisplayNameAttribute(My.Resources.ValuesDisplay),
                                      New DescriptionAttribute(My.Resources.ValuesDescription))

        MetadataStore.AddAttributeTable(build.CreateTable)
    End Sub

End Class
